package momo.multitree.simulation;

import java.io.FileReader;

import momo.multitree.structure.Graph;
import momo.multitree.structure.Tree;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class OptStarTreeFrameWork {
	
	private Log log = LogFactory.getLog(OptStarTreeFrameWork.class);
	
	private int sizes[] = {5, 6, 7, 8, 9, 10, 12, 15, 20, 25, 30, 40, 50};
	private String[] filenames;
	
	public OptStarTreeFrameWork() {
		filenames = new String[ sizes.length*100 ];
		int counter = 0;
		for(int i=0; i<sizes.length; i++)
		{
			for(int j=0; j<100; j++)
				filenames[ j + (counter*100) ] = sizes[i]+"_node_symmetric_noleaf_dataset_" + (j+1) +".txt";
			counter ++;
		}
	}
	
	public void run() {
		for(String filename: filenames)
		{
			try
			{
				Graph g = new Graph(new FileReader("dataset/"+filename));				
				OptStarTree sim = new OptStarTree(g);
				Tree bestTree = sim.optimizeTree();
				Tree bestLatTree = sim.getBestLatTree();
				Tree bestCostTree = sim.getBestCostTree();
				Tree bestStabTree = sim.getBestStabTree();
				log.info(filename+", " + this.displayInfo(bestLatTree, bestCostTree, bestStabTree, bestTree));
			}catch(Exception e)
			{
				log.error("Error on filename: " + filename);
				e.printStackTrace();
			}
		}
	}
	
	public String displayInfo(Tree bestLatTree, Tree bestCostTree, Tree bestStabTree, Tree bestTree)
	{
		return bestLatTree.compWeightedLatency() + ", " +
				bestLatTree.compCost(false) + ", " +
				bestLatTree.compStability() + ", " +
				bestCostTree.compWeightedLatency() + ", " +
				bestCostTree.compCost(false) + ", " +
				bestCostTree.compStability() + ", " +
				bestStabTree.compWeightedLatency() + ", " +
				bestStabTree.compCost(false) + ", " +
				bestStabTree.compStability() + ", " +
				bestTree.compWeightedLatency() + ", " +
				bestTree.compCost(false) + ", " +
				bestTree.compStability();
	}
	
	public static void main(String args[])
	{
		OptStarTreeFrameWork app = new OptStarTreeFrameWork();
		app.run();
	}
	
}
